package com.quasar.hpatient.dialog;

import android.app.Activity;
import android.view.View;

import com.quasar.hpatient.R;

import java.util.Arrays;
import java.util.List;

import lib.quasar.base.dialog.BaseDialog;
import lib.quasar.widget.wheel.WheelView;

/**
 * description: 血型
 * created by kalu on 2018/4/10 15:02
 */
public class BloodtypeDialog extends BaseDialog implements View.OnClickListener {

    private final List<String> mData = Arrays.asList("A型, RH阳性",
            "A型, RH阴性",
            "B型, RH阳性",
            "B型, RH阴性",
            "AB型, RH阳性",
            "AB型, RH阴性",
            "O型, RH阳性",
            "O型, RH阴性");
    private String mText = mData.get(0);
    /***************************************************/

    private OnDialogChangeListener listener;

    public BloodtypeDialog(Activity activity) {
        super(activity);
    }

//    @Override
//    public void onBackPressed() {
//    }

    @Override
    protected int initView() {
        return R.layout.layout_dialog_bloodtype;
    }

    @Override
    public void show() {
        super.show();
//        setCanceledOnTouchOutside(false);
//        setCancelable(false);

        if (null == listener) return;
        WheelView wheel = findViewById(R.id.layout_dialog_bloodtype_wheel);
        if (null != wheel) {
            wheel.setOnWheelChangeListener((index, str) -> mText = str);
        }
    }

    @Override
    public void dismiss() {

        if (null != listener) {
            listener.onDialogChange(mText);
        }

        super.dismiss();
    }

    @Override
    public void cancel() {

        if (null != listener) {
            listener.onDialogChange(mText);
        }

        super.cancel();
    }

    @Override
    protected void initData() {

        findViewById(R.id.layout_dialog_bloodtype_back).setOnClickListener(this);
        findViewById(R.id.layout_dialog_bloodtype_ok).setOnClickListener(this);

        WheelView wheel = findViewById(R.id.layout_dialog_bloodtype_wheel);
        if (null != wheel) {
            wheel.setList(mData);
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.layout_dialog_bloodtype_back:
                dismiss();
                break;
            case R.id.layout_dialog_bloodtype_ok:
                dismiss();
                break;
        }
    }

    public void setOnDialogChangeListener(OnDialogChangeListener listener) {
        this.listener = listener;
    }

    public interface OnDialogChangeListener {

        void onDialogChange(String str);
    }
}
